dnl
dnl $Id: config.m4 17 2009-11-13 18:44:53Z bpd $
dnl

PHP_ARG_WITH(yaml, [whether to enable LibYAML suppot],
[  --with-yaml[[=DIR]]       Enable LibYAML support.
                          DIR is the path to LibYAML install prefix], yes, yes)


if test "$PHP_YAML" != "no"; then

  if test -z "$AWK"; then
    AC_PATH_PROGS(AWK, awk gawk nawk, [no])
  fi
  if test -z "$SED"; then
    AC_PATH_PROGS(SED, sed gsed, [no])
  fi

  if test -r "$PHP_YAML/include/yaml.h"; then
    PHP_YAML_DIR="$PHP_YAML"
  else
    AC_MSG_CHECKING([for yaml in default path])
    for i in /usr /usr/local; do
      if test -r "$i/include/yaml.h"; then
        PHP_YAML_DIR=$i
        AC_MSG_RESULT([found in $i])
        break
      fi
    done
    if test -z "$PHP_YAML_DIR"; then
      AC_MSG_ERROR([not found])
    fi
  fi

  PHP_ADD_INCLUDE($PHP_YAML_DIR/include)

  export OLD_CPPFLAGS="$CPPFLAGS"
  export CPPFLAGS="$CPPFLAGS $INCLUDES -DHAVE_YAML"
  AC_CHECK_HEADER([yaml.h], [], AC_MSG_ERROR(['yaml.h' header not found]))
  PHP_SUBST(YAML_SHARED_LIBADD)

  PHP_ADD_LIBRARY_WITH_PATH(yaml, $PHP_YAML_DIR/lib, YAML_SHARED_LIBADD)
  export CPPFLAGS="$OLD_CPPFLAGS"

  export OLD_CPPFLAGS="$CPPFLAGS"
  export CPPFLAGS="$CPPFLAGS $INCLUDES -DHAVE_YAML"
  export CPPFLAGS="$OLD_CPPFLAGS"


  PHP_SUBST(YAML_SHARED_LIBADD)
  AC_DEFINE(HAVE_YAML, 1, [ ])
  PHP_NEW_EXTENSION(yaml, yaml.c , $ext_shared)
fi
